-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail explanatory assertion group on empty assertionCreator #938
Fail explanatory assertion group on empty assertionCreator #938
Conversation
// not using addAssertionsCreatedBy on purpose so that we don't append a failing assertion | ||
collectingExpect.assertionCreatorOrNull() | ||
if(collectingExpect.getAssertions().isEmpty()) { | ||
it.collectAssertions(container, None, assertionCreatorOrNull).failing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to make collectAssertions(...)
fail the explanatory group when the assertionCreator doesn't create any assertions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like a reasonable thing. That an explanatory group can fail is rather a new thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize I'm not actually sure how to modify the builder to accomplish this.
I'm looking at AssertionOptionExplanatoryExtensions.kt
and I'm not sure how to get the extension method .collectAssertions
to produce a failing final step.
My naive attempt:
fun <T, G : ExplanatoryAssertionGroupType, R> AssertionsOption<G, R>.collectAssertions(
container: AssertionContainer<*>,
maybeSubject: Option<T>,
assertionCreator: Expect<T>.() -> Unit
): R {
val collectingExpect = CollectingExpect<T>(None, container.components)
// not using addAssertionsCreatedBy on purpose so that we don't append a failing assertion
collectingExpect.assertionCreator()
return withAssertions(container.collectForCompositionBasedOnSubject(maybeSubject, assertionCreator))
.let {
if(collectingExpect.getAssertions().isEmpty()) it.failing
else it
}
}
has issues because the return type is the generic type R
and it doesn't recognize .failing
. I'm not really understanding here how the builder pattern is implemented here with the generic AssertionsOption<G,R>
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to restrict R with an upper bound of ExplanatoryGroup.FinalStep.kt in AssertionOptionExplanatoryExtensions.kt.
So like the following:
fun <T, G : ExplanatoryAssertionGroupType, R : ExplanatoryGroup.FinalStep> AssertionsOption<G, R>.collectAssertions(...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the above type signature the compiler complained about two things:
- It expects the method to return
R
but the inferred type isExplanatoryGroup.FinalStep
- Elsewhere in the code, in 4 other places, it complains about the upper bound
R : ExplanatoryGroup.FinalStep
, sayingExplanatoryAssertionGroupFinalStep
isn't a subtype ofExplanatoryGroup.FinalStep
. I think the problem is that the type optionswithDefaultType
,withWarningType
,withInformationType
andwithType
all have a type signatureAssertionsOption<T, ExplanatoryAssertionGroupFinalStep>
, at least for now. I saw your notes about replacingExplanatoryAssertionGroupFinalStep
withExplanatoryGroup.FinalStep
before version1.0.0
.
So I had to use the following to satisfy the compiler.
fun <T, G : ExplanatoryAssertionGroupType, R : ExplanatoryAssertionGroupFinalStep> AssertionsOption<G, R>.collectAssertions(
container: AssertionContainer<*>,
maybeSubject: Option<T>,
assertionCreator: Expect<T>.() -> Unit
) : ExplanatoryAssertionGroupFinalStep {
// ...
}
However this generates a warning on compilation. Am I approaching this in the right way? Do we suppress/ignore the warning or do something else?
Codecov Report
@@ Coverage Diff @@
## master #938 +/- ##
==========================================
+ Coverage 91.34% 91.40% +0.06%
==========================================
Files 429 429
Lines 4299 4295 -4
Branches 219 218 -1
==========================================
- Hits 3927 3926 -1
+ Misses 323 320 -3
Partials 49 49
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@wordhou sorry, I am quite busy at the moment, going to look into it hopefully soon |
Resolves #933. Whenever an assertionCreator is taken as an argument of an expectation, an explanatory group is created that describes the assertions created. If no assertions are created, then an empty lambda failure hint is given. This PR makes the explanatory group fail when the empty lambda failure hint is given, and then removes the
createEmptyAssertionHintIfNecessary
from the assertion creators.I confirm that I have read the Contributor Agreements v1.0, agree to be bound on them and confirm that my contribution is compliant.